package com.javasm.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;

/**
 * @Author：MoDebing
 * @Version：1.0
 * @Date：2022-09-04-20:04
 * @Description:授权服务器
 */
@Configuration
@EnableAuthorizationServer
public class AuthonrizationServiceConfig extends AuthorizationServerConfigurerAdapter {

     @Autowired
    PasswordEncoder passwordEncoder;

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                .withClient("modebing")
                //配置client_secret
                .secret(passwordEncoder.encode("123456"))
                // 配置访问有效期
                .accessTokenValiditySeconds(3600)
                //重定向地址
                .redirectUris("https://www.baidu.com")
                .scopes("all")
                // 四种授权模式
                .authorizedGrantTypes("client_credentials", "refresh_token","password","authorization_code","implicit");

    }
}
